Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
trying to create a prototype to access my Api (Axios) globally in [vue.js 3] and I always get this error: "Cannot read properties of undefined"

the error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'get')

the main files

the axios file

import axios from "axios";

const token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOJQ......";

export default axios.create({
  baseURL: "https://api.themoviedb.org/3",
  headers: {
    authorization: `Bearer ${token}`,
  },
});

the main.js file

import api from "@/data/db";

const app = createApp({});
app.config.globalProperties.$http = api;

the home file

async mounted() {
    const response = await this.$http.get("/movie/550");
    console.log(response);
},
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Check out this sandbox. It logs a promise in the console, doesn't give the undefined error. Try putting your actual key in the db.js file and check if you can make a request to the API.

I think the problem in your code is with this line const app = createApp({});

You need to pass a component with the mounted() hook in it as an object param to the createApp function. Then you need to mount the app.

import api from "@/data/db";
import Home from "@/Home.vue";
const app = createApp(Home);
app.config.globalProperties.$http = api;
app.mount("#app"); // Provide a valid html id that exists in your index.html file
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda